module RoutesHelper
  
  require 'scrobbler'
  require 'active_support/all'
  
  def route_is_outdated (buildDate)
    
    # How much days until a route is out of date?
    outOfDate = 180
    
    now = DateTime.now
    diff = now - buildDate
    diff.to_i > outOfDate
  end
  
  def display_redo_route(route)
    if route.rework
			('<span class="greenlabel">' + "\u2713" + '</span>').html_safe
		else
			if route_is_outdated (route.build)
				'<span class="yellowlabel">-</span>'.html_safe
			else
				'<span class="redlabel">X</span>'.html_safe
			end 
		end
  end
  
  def generate_route_name(starting_at = "Metallica")
    # Starting artist
    artist = Scrobbler::Artist.new(starting_at)
    item = artist.similar[rand(artist.similar.length)].name
    
    if item.nil?
      item = starting_at
    end
    
    snd_artist = Scrobbler::Artist.new(item)
    item2 = snd_artist.similar[rand(snd_artist.similar.length)].name
    
    if item2.nil?
      item2 = starting_at
    end

    final_artist = Scrobbler::Artist.new(item2)
  
    if final_artist.nil?
      final_artist = starting_at
    end
    
    name = final_artist.top_tracks[rand(final_artist.top_tracks.length)].name
    
    if name.nil?
      name = ""
    end
    
    name.html_safe
  end
  
end
